<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:messages showDetail="true" id="msgs"/>

            <p:panel header="Some Info">
                <h:panelGrid columns="2" rendered="#{!logManagerBean.isFirstLoggedIn(workspaceManagerBean.currentStaff.systemUserAccount.id)}">
                    <h:outputLabel value="You last logged in at"/>
                    <h:outputText value="#{logManagerBean.getLastLoginTimeString(workspaceManagerBean.currentStaff.systemUserAccount.id)}"/>
                </h:panelGrid>

                <h:outputText value="Welcome to Merlion ERP System." rendered="#{logManagerBean.isFirstLoggedIn(workspaceManagerBean.currentStaff.systemUserAccount.id)}"/>
            </p:panel>

            <p:fieldset legend="Announcements" toggleable="true">  
                <p:dataTable value="#{annouceManagerBean.getRecentAtMostFiveAnns(workspaceManagerBean.currentStaff.systemUserAccount.id)}" var="ann">
                    <f:facet name="header">
                        Recent Announcements
                    </f:facet>

                    <p:column headerText="Title"
                              filterBy="#{ann.title}">
                        <p:commandLink value="#{ann.title}" ajax="false" action="#{annouceManagerBean.viewOneMyAnn(ann.id)}"/>
                    </p:column>

                    <p:column headerText="Posted On"
                              sortBy="#{ann.formattedDate}">
                        <h:outputText value="#{ann.formattedDate}"/>
                    </p:column>

                    <p:column headerText="Posted By">
                        <h:outputText value="#{annouceManagerBean.getPosterFullName(ann.posterId)}"/>
                    </p:column>
                </p:dataTable>
                <p:commandButton value="View All" actionListener="#{workspaceManagerBean.redirectToAnnView}"/>
            </p:fieldset>

            <p:fieldset legend="Jobs" toggleable="true">  
                <p:dataTable value="#{jobManagerBean.getAllMyPendingJobsDESC(workspaceManagerBean.currentStaff.systemUserAccount.id)}" var="job"
                             style="width: 100%"
                             paginator="true" rows="5"  
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="5,8,10">
                    <f:facet name="header">
                        Pending Jobs
                    </f:facet>

                    <p:column headerText="Job Type"
                              filterBy="#{job.jobType}" >
                        <h:outputText value="#{job.jobType}"/>
                    </p:column>

                    <p:column headerText="Title"
                              filterBy="#{job.title}" >
                        <p:commandLink value="#{job.title}" ajax="false" action="#{jobManagerBean.viewMyJobListOne(job.id)}"/>
                    </p:column>

                    <p:column headerText="Created On"
                              sortBy="#{job.formattedCreatedDate}">
                        <h:outputText value="#{job.formattedCreatedDate}"/>
                    </p:column>

                </p:dataTable>  
                <p:commandButton value="View All" actionListener="#{workspaceManagerBean.redirectToViewMyJobList}"/>
            </p:fieldset>

            <p:fieldset legend="Internal Messages" toggleable="true">  
                <p:dataTable value="#{msgManagerBean.getNewRcvedUnread(workspaceManagerBean.currentStaff.systemUserAccount.id)}" var="msg"
                             style="width: 100%"
                             paginator="true" rows="15"  
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="15,20,25">
                    <f:facet name="header">
                        Recent Announcements
                    </f:facet>

                    <p:column>
                        <h:graphicImage value="./../images/msg-rd.gif" rendered="#{msg.haveRead}"/>
                        <h:graphicImage value="./../images/msg-unread.gif" rendered="#{!msg.haveRead}"/>
                    </p:column>

                    <p:column headerText="Subject"
                              filterBy="#{msg.subject}">
                        <p:commandLink value="#{msg.subject}" ajax="false" action="#{msgManagerBean.viewOneRcvedMsg(msg.id)}"/>
                    </p:column>

                    <p:column headerText="Sender"
                              filterBy="#{msgManagerBean.getSenderFullName(msg.senderAccId)}">
                        <h:outputText value="#{msgManagerBean.getSenderFullName(msg.senderAccId)}"/>
                    </p:column>

                    <p:column headerText="Time"
                              sortBy="#{msg.formattedDate}">
                        <h:outputText value="#{msg.formattedDate}"/>
                    </p:column>
                </p:dataTable>  
                <p:commandButton value="View All" actionListener="#{workspaceManagerBean.redirectToViewAllRcved}"/>
            </p:fieldset>

<!--            <p:panel header="Need to delete: initial system jobs.. no hardcoding">
                <p:commandButton value="ATP Check SO" ajax="true" action="{jobManagerBean.addJobATPSO(187)}"/>
                <p:commandButton value="ATP Check SQ" ajax="true" action="{jobManagerBean.addJobATPSQ(170)}"/>
                <p:commandButton value="CC Check" ajax="true" action="{jobManagerBean.addJobCC(187)}"/>
            </p:panel>-->
        </h:form>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
